package com.example.springbootsfzy.controller.liujinping;

import com.example.springbootsfzy.domain.CoursePayments;
import com.example.springbootsfzy.service.liujinping.CoursePaymentsService;
import com.example.springbootsfzy.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
//课程支付表
@RestController
@RequestMapping("/payments")
public class CoursePaymentsController {
    @Autowired
    private CoursePaymentsService coursePaymentsService;

    // 添加课程支付信息
    @PostMapping
    public R addCoursePayments(@RequestBody CoursePayments coursePayments) {
        int result = coursePaymentsService.addCoursePayments(coursePayments);
        if (result > 0) {
            return R.ok("添加课程支付信息成功");
        }
        return R.fail("添加课程支付信息失败");
    }

    @DeleteMapping
    public R deleteCoursePayments(Long id) {
        int result = coursePaymentsService.deleteCoursePayments(id);
        if (result > 0) {
            return R.ok("删除课程支付信息成功");
        }
        return R.fail("删除课程支付信息失败");
    }

    @PutMapping
    public R updateCoursePayments(@RequestBody CoursePayments coursePayments) {
        int result = coursePaymentsService.updateCoursePayments(coursePayments);
        if (result > 0) {
            return R.ok("更新课程支付信息成功");
        }
        return R.fail("更新课程支付信息失败");
    }

    @PatchMapping
    public R updateCoursePaymentsActive(@RequestBody CoursePayments coursePayments) {
        int result = coursePaymentsService.updateCoursePaymentsActive(coursePayments);
        if (result > 0) {
            return R.ok("更新课程支付信息成功");
        }
        return R.fail("更新课程支付信息失败");
    }

    @GetMapping("/getAllCoursePayments")
    public R getAllCoursePayments() {
        return R.ok(coursePaymentsService.getAllCoursePayments());
    }

    @GetMapping("/getCoursePayments")
    public R getCoursePayments(Long id) {
        return R.ok(coursePaymentsService.getCoursePayments(id));
    }

}
